package com.wl.eb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wl.eb.mapper.EbUserMapper;
import com.wl.eb.module.EbUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
public class LoginService {
    @Resource
    private EbUserMapper ebUserMapper;
    //根据用户名和密码返回查询是否存在该用户
    public EbUser login(EbUser ebUser){
        List<EbUser> ebUserList = ebUserMapper.selectList(new QueryWrapper<EbUser>()
                .eq("Eu_User_Name", ebUser.getEuUserName())
                .eq("Eu_Password", ebUser.getEuPassword()));
        if (ebUserList.size()==0){
            throw new RuntimeException("登录失败");
        }
        return ebUserList.get(0);
    }

    public boolean register(EbUser ebUser){
        //添加用户id，随机生成10个字符的字符串
        String userId = UUID.randomUUID().toString().replace("-","").substring(0,10);
        ebUser.setEuUserId(userId);
        //添加用户状态，默认是普通用户
        ebUser.setEuStatus(1);

        int result = ebUserMapper.insert(ebUser);
        return result>0?true:false;
    }

}
